<div id="main-content">
  <div class="container-fluid">
    <div class="row-fluid">
			<div class="span12">
				<div class="nonboxy-widget">
					<div class="widget-head">
						<h5><i class="black-icons blocks_images"></i><?=$title?></h5>
					</div>
					<div class="widget-content">
						<div class="widget-box">
              <?=$this->form_eksternal->form_open("", 'class=" form-horizontal well" id="formoutlet"', 
                      array("id_detail" => $detail[0]->id_checklist_keterangan))?>
								<fieldset>
									<div class="control-group">
										<label class="control-label">Name</label>
										<div class="controls">
                      <?=$this->form_eksternal->form_input('name', $detail[0]->name, 'class="span4"')?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Sort</label>
										<div class="controls">
                      <?=$this->form_eksternal->form_input('sort', $detail[0]->sort, 'class="span4"')?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Fase</label>
										<div class="controls">
                      <?=$this->form_eksternal->form_dropdown('fase', $fase, array($detail[0]->id_checklist_fase), "id='fase'")?>
										</div>
									</div>
                  <div class="control-group">
										<label class="control-label">Level 1</label>
                    <div class="controls">
                      <?php
                      if($detail[0]->level2 > 0){
                        $view1 = $this->global_models->get_field("d_checklist_keterangan", "name", array(
                              "level1"            => $detail[0]->level1,
                              "level2"            => 0,
                              "id_checklist_fase" => $detail[0]->id_checklist_fase
                          ));
                        $sign1 = $detail[0]->level1;
                      }
                      ?>
                      <?=$this->form_eksternal->form_input('level1', $view1, 'id="level1"')?>
                      <?=$this->form_eksternal->form_input('id_level1', $sign1, 'id="id_level1" style="display: none"')?>
                    </div>
                  </div>
                  <div class="control-group">
										<label class="control-label">Level 2</label>
                    <div class="controls">
                      <?php
                      if($detail[0]->level3 > 0){
                        $view2 = $this->global_models->get_field("d_checklist_keterangan", "name", array(
                              "level1"            => $detail[0]->level1,
                              "level2"            => $detail[0]->level2,
                              "level3"            => 0,
                              "id_checklist_fase" => $detail[0]->id_checklist_fase
                          ));
                        $sign2 = $detail[0]->level2;
                      }
                      ?>
                      <?=$this->form_eksternal->form_input('level2', $view2, 'id="level2"')?>
                      <?=$this->form_eksternal->form_input('id_level2', $sign2, 'id="id_level2" style="display: none"')?>
                    </div>
                  </div>
                  <div class="control-group">
										<label class="control-label">Level 3</label>
                    <div class="controls">
                      <?php
                      if($detail[0]->level4 > 0){
                        $view3 = $this->global_models->get_field("d_checklist_keterangan", "name", array(
                              "level1"            => $detail[0]->level1,
                              "level2"            => $detail[0]->level2,
                              "level3"            => $detail[0]->level3,
                              "level4"            => 0,
                              "id_checklist_fase" => $detail[0]->id_checklist_fase
                          ));
                        $sign3 = $detail[0]->level3;
                      }
                      ?>
                      <?=$this->form_eksternal->form_input('level3', $view3, 'id="level3"')?>
                      <?=$this->form_eksternal->form_input('id_level3', $sign3, 'id="id_level3" style="display: none"')?>
                    </div>
                  </div>
                  <div class="control-group">
										<label class="control-label">Level 4</label>
                    <div class="controls">
                      <?php
                      if($detail[0]->level5 > 0){
                        $view4 = $this->global_models->get_field("d_checklist_keterangan", "name", array(
                              "level1"            => $detail[0]->level1,
                              "level2"            => $detail[0]->level2,
                              "level3"            => $detail[0]->level3,
                              "level4"            => $detail[0]->level4,
                              "level5"            => 0,
                              "id_checklist_fase" => $detail[0]->id_checklist_fase
                          ));
                        $sign4 = $detail[0]->level4;
                      }
                      ?>
                      <?=$this->form_eksternal->form_input('level4', $view4, 'id="level4"')?>
                      <?=$this->form_eksternal->form_input('id_level4', $sign4, 'id="id_level4" style="display: none"')?>
                    </div>
                  </div>
                  <div class="control-group">
                    <label class="control-label">Check</label>
                    <div class="controls">
                      <label class="checkbox">
                        <?php
                        if($detail[0]->cek == 1){
                          print $this->form_eksternal->form_checkbox('cek', 1, TRUE, " id='cekprivilege' ");
                          $cek = "display:block;";
                        }
                        else{
                          print $this->form_eksternal->form_checkbox('cek', 1, FALSE, " id='cekprivilege' ");
                          $cek = "display:none;";
                        }
                        ?> Active
                      </label>
                    </div>
                  </div>
                  <div class="control-group" id='showprivilege' style='<?=$cek?>'>
										<label class="control-label">Privilege</label>
										<div class="controls">
                      <?=$this->form_eksternal->form_autocomplate("privilege", "id_privilege", "privilege", "id_privilege", site_url("dev_checklist/autoprivilege"), "", 0)?>
										</div>
									</div>
								</fieldset>
								<div class="form-actions">
									<button class="btn btn-primary" type="submit">Save changes</button>
									<button class="btn" onclick="history.go(-1);return false;">Cancel</button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
  </div>
</div>
<script>
  $(function () {
    $("#cekprivilege").click(function(){
      $("#showprivilege").fadeToggle();
    });
    
    $( "#level1" ).autocomplete({
      source: "<?=  site_url("dev-checklist/autolevel")?>/1/"+$("#fase").val(),
      minLength: 1,
      select: function( event, ui ) {
        $("#id_level1").val(ui.item.id);
        $( "#level2" ).autocomplete('option', 'source', "<?=  site_url("dev-checklist/autolevel")?>/2/"+$("#fase").val()+"/"+$("#id_level1").val()+"/");
      }
    });
    
    $( "#level2" ).autocomplete({
      source: "<?=  site_url("dev-checklist/autolevel")?>/2/"+$("#fase").val()+"/"+$("#id_level1").val()+"/",
      minLength: 1,
      select: function( event, ui ) {
        $("#id_level2").val(ui.item.id);
        $( "#level3" ).autocomplete('option', 'source', "<?=  site_url("dev-checklist/autolevel")?>/2/"+$("#fase").val()+"/"+$("#id_level1").val()+"/"+$("#id_level2").val());
      }
    });
    
    $( "#level3" ).autocomplete({
      source: "<?=  site_url("dev-checklist/autolevel")?>/3/"+$("#fase").val()+"/"+$("#id_level1").val()+"/"+$("#id_level2").val(),
      minLength: 1,
      select: function( event, ui ) {
        $("#id_level3").val(ui.item.id);
        $( "#level4" ).autocomplete('option', 'source', "<?=  site_url("dev-checklist/autolevel")?>/2/"+$("#fase").val()+"/"+$("#id_level1").val()+"/"+$("#id_level2").val()+"/"+$("#id_level3").val());
      }
    });
    
    $( "#level4" ).autocomplete({
      source: "<?=  site_url("dev-checklist/autolevel")?>/4/"+$("#fase").val()+"/"+$("#id_level1").val()+"/"+$("#id_level2").val()+"/"+$("#id_level3").val(),
      minLength: 1,
      select: function( event, ui ) {
        $("#id_level4").val(ui.item.id);
      }
    });
    
    $("#fase").change(function(){
      $( "#level1" ).autocomplete('option', 'source', "<?=  site_url("dev-checklist/autolevel")?>/1/"+$("#fase").val());
      $( "#level2" ).autocomplete('option', 'source', "<?=  site_url("dev-checklist/autolevel")?>/2/"+$("#fase").val()+"/"+$("#id_level1").val()+"/");
      $( "#level3" ).autocomplete('option', 'source', "<?=  site_url("dev-checklist/autolevel")?>/2/"+$("#fase").val()+"/"+$("#id_level1").val()+"/"+$("#id_level2").val());
      $( "#level4" ).autocomplete('option', 'source', "<?=  site_url("dev-checklist/autolevel")?>/2/"+$("#fase").val()+"/"+$("#id_level1").val()+"/"+$("#id_level2").val()+"/"+$("#id_level3").val());
    });
    
  });
</script>